﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NewsEntity.Models;
using NewsSevicer.Interface;
using NewsSevicer.ResultClass;
using System;
using System.Collections.Generic;

namespace NewsWebsite.Controllers
{
    [Route("api/test")]
    [ApiController]
    public class TestController : ControllerBase
    {
        private IOnlineUserService  _OnlineUserService { get; set; }
        public TestController(IOnlineUserService onlineUserService) { 
         _OnlineUserService = onlineUserService;
        }

        [HttpGet("adduseronline")]
        public IActionResult Get() {
            Guid id = Guid.NewGuid();
            OnlineUsers onlineUser = new OnlineUsers {Username ="test",Password= "123456" };
                              
           var res =  _OnlineUserService.CreateUser(onlineUser);

            return Ok(res);

        }
        [HttpGet("getUserinfo")]
        public object Get(string id) {
           
         var a =   _OnlineUserService.GetUserById(id);
            return a;


        }

        // 定义文章类
        public class Article
        {
            public int Id { get; set; }
            public string Title { get; set; }
            public string Content { get; set; }
            public string Author { get; set; }
            public string PublishDate { get; set; }
        }

        // 返回测试文章数据的接口
        [HttpGet("getArticleList")]
        public ResultData GetArticles()
        {
            // 创建一些测试数据
            var articles = new List<Article>
            {
                new Article
                {
                    Id = 1,
                    Title = "如何学习C#",
                    Content = "C# 是一种现代编程语言，适用于多种开发场景，包括Web、桌面和移动应用开发。",
                    Author = "张三",
                    PublishDate = "2024-12-27"
                },
                new Article
                {
                    Id = 2,
                    Title = "ASP.NET Core 入门",
                    Content = "ASP.NET Core 是一个跨平台的框架，用于构建现代化的Web应用程序。",
                    Author = "李四",
                    PublishDate = "2024-12-26"
                },
                new Article
                {
                    Id = 3,
                    Title = "设计模式简介",
                    Content = "设计模式是一种解决软件开发中常见问题的最佳实践，包括单例模式、工厂模式等。",
                    Author = "王五",
                    PublishDate = "2024-12-25"
                },
                new Article
                {
                    Id = 4,
                    Title = "EF Core 数据库操作",
                    Content = "Entity Framework Core 是一个对象关系映射（ORM）框架，用于与数据库交互。",
                    Author = "赵六",
                    PublishDate = "2024-12-24"
                },
                new Article
                {
                    Id = 5,
                    Title = "微服务架构简介",
                    Content = "微服务架构是一种设计方法，将应用程序划分为一组小型服务，每个服务独立运行。",
                    Author = "周七",
                    PublishDate = "2024-12-23"
                }
            };

            // 返回文章列表
            return  new ResultData {code=200,data=articles,message="成功" };
        }

    }
}
